
local mt = ac.skill['叉状闪电']
mt.art = [[ReplaceableTextures\CommandButtons\BTNOrbOfLightning.blp]]
mt.targettype = "物体"
mt.range = 900
mt.damage = 100
mt.damage_area = 300
mt.damage_count = 5
mt.damage_type = '魔法'
mt.lightning1 = '叉状闪电'
mt.target_art = [[Abilities\Weapons\Bolt\BoltImpact.mdl]]

function mt:on_cast_shot()
    local hero = self.owner
    local target = self.target
    self:create_lightning(target)
end


function mt:create_lightning(target,count)
    local hero = self.owner
    local count = count or self.damage_count
    local selector = ac.selector('unit'):range(target,300):enemy(hero)
    if target.type=='unit' then
        count = count - 1
        self:shot_lightning(target)
        selector = selector:is_not(target)
    end
    for a=1,count do
        target = selector:random()
        selector = selector:is_not(target)
        if target then
            self:shot_lightning(target)
        else
            return
        end
    end
end

function mt:shot_lightning(target)
    local hero = self.owner
    ac.lightning({
        id = self.lightning1,
        from = hero,
        to = target,
        time = 0.25
    })
    target:add_effect(self.target_art):remove()
    ac.wait(150,function()
        target:damage{
            damage_type = self.damage_type,
            source = hero,
            damage = self.damage,
            skill = self,
        }
    end)

end
